package com.py.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.py.admin.mapper.AdChannelLabelMapper;
import com.py.admin.service.AdChannelLabelService;
import com.py.apis.wemedia.IChannelClient;
import com.py.model.admin.dtos.ChannelDto;
import com.py.model.admin.pojos.AdChannelLabel;
import com.py.model.common.dtos.ResponseResult;
import com.py.model.common.enums.AppHttpCodeEnum;
import com.py.model.wemedia.pojos.WmChannel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class AdChannelLabelServiceImpl extends ServiceImpl<AdChannelLabelMapper, AdChannelLabel> implements AdChannelLabelService {


    //注入feign调用方法
    @Resource
    private IChannelClient channelClient;

    @Override
    public ResponseResult saveChannel(WmChannel wmChannel) {

        //判断 参数不能为空
        if (wmChannel == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }

        //当参数不为空则feign调用IChannelClient存入数据库wmChannel表
        channelClient.save(wmChannel);
        log.info("新增频道");

        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }


    /**
     * 分页查询
     * @param dto
     * @return
     */
    @Override
    public ResponseResult findAll(ChannelDto dto) {


        //调用feign接口
        ResponseResult responseResult = channelClient.findAll(dto);

        //取出封装的wmChannel对象
        Object data = responseResult.getData();

        return ResponseResult.okResult(data);

    }


    /**
     * 修改
     * @param wmChannel
     */
    @Override
    public void updateByName(WmChannel wmChannel) {

        channelClient.update(wmChannel);
    }


    /**
     * 删除频道
     * @param id
     */
    @Override
    public void deleteChannel(Integer id) {

        //判断 参数不能为空
        if (id == null) {
            return;
        }
        //当参数不为空则feign调用IChannelClient删除数据
        channelClient.delete(id);
        log.info("删除频道");

    }





}
